using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using EstimationStudio.Core;

namespace EstimationStudio.Core.Test
{
	[TestClass]
	public sealed class EstimationTests
	{
		[TestMethod]
		public void CreateFeature ()
		{
			Feature feature = new Feature();
			feature.BestCase = 1.25;
			feature.NominalCase = 1.5;
			feature.WorstCase = 2.0;

			Assert.IsNotNull(feature);
			Assert.AreEqual(String.Empty, feature.Name);
			Assert.AreEqual(String.Empty, feature.Description);
			Assert.AreEqual(1.25, feature.BestCase);
			Assert.AreEqual(1.5, feature.NominalCase);
			Assert.AreEqual(2.0, feature.WorstCase);
			Assert.AreEqual(1.54, feature.ExpectedCase);
		}

        [TestMethod]
		public void AddFeaturesToEstimate ()
		{
			Estimate estimate = new Estimate();

			Feature feature1 = new Feature();
			feature1.BestCase = 0.0;
			feature1.BestCase = 0.0;
			feature1.BestCase = 0.0;
			
			estimate.Features.Add(feature1);

			Feature feature2 = new Feature();
			feature2.BestCase = 0.0;
			feature2.BestCase = 0.0;
			feature2.BestCase = 0.0;
			estimate.Features.Add(feature2);

			Feature feature3 = new Feature();
			feature3.BestCase = 0.0;
			feature3.BestCase = 0.0;
			feature3.BestCase = 0.0;
			estimate.Features.Add(feature3);

			Assert.AreEqual(3, estimate.Features.Count);
		}

        [TestMethod]
		public void CreateRatings ()
		{
			AdjustmentVariability ratings = new AdjustmentVariability(1.22, 1.09, 0.93, 0.86, 0.78);
			Assert.IsNotNull(ratings);
			Assert.AreEqual(1.22, ratings[Rating.VeryLow]);
			Assert.AreEqual(1.09, ratings[Rating.Low]);
			Assert.AreEqual(1.0, ratings[Rating.Nominal]);
			Assert.AreEqual(0.93, ratings[Rating.High]);
			Assert.AreEqual(0.86, ratings[Rating.VeryHigh]);
			Assert.AreEqual(0.78, ratings[Rating.ExtraHigh]);
		}

        [TestMethod]
		public void CreateAdjustmentFactor ()
		{
			AdjustmentFactor adjustmentFactor = new AdjustmentFactor("Application Experience", "Application Experience description", new AdjustmentVariability(1.22, 1.10, 0.88, 0.81, Double.NaN));
			Assert.IsNotNull(adjustmentFactor);
			Assert.AreEqual("Application Experience", adjustmentFactor.Name);
			Assert.AreEqual(1.22, adjustmentFactor.AdjustmentVariability[Rating.VeryLow]);
			Assert.AreEqual(1.10, adjustmentFactor.AdjustmentVariability[Rating.Low]);
			Assert.AreEqual(1.0, adjustmentFactor.AdjustmentVariability[Rating.Nominal]);
			Assert.AreEqual(0.88, adjustmentFactor.AdjustmentVariability[Rating.High]);
			Assert.AreEqual(0.81, adjustmentFactor.AdjustmentVariability[Rating.VeryHigh]);
			Assert.AreEqual(Double.NaN, adjustmentFactor.AdjustmentVariability[Rating.ExtraHigh]);
		}

        [TestMethod]
		public void CreateErrorVariability ()
		{
			ErrorVariability errorVariability = new ErrorVariability(0.0, 0.0);
			Assert.IsNotNull(errorVariability);
			Assert.AreEqual(0.0, errorVariability.Low);
			Assert.AreEqual(0.0, errorVariability.High);
			Assert.AreEqual(Double.NaN, errorVariability.Range);

			errorVariability = new ErrorVariability(0.25, 4.0);
			Assert.AreEqual(0.25, errorVariability.Low);
			Assert.AreEqual(4.0, errorVariability.High);
			Assert.AreEqual(16, errorVariability.Range);
		}

        [TestMethod]
		public void MultiplyErrorVariability ()
		{
			ErrorVariability errorVariability = new ErrorVariability(.25, 4.0);
			errorVariability *= 2;

			Assert.AreEqual(0.5, errorVariability.Low);
			Assert.AreEqual(8.0, errorVariability.High);
			Assert.AreEqual(16.0, errorVariability.Range);
		}
	}
}